<template>
	<view class="container">

		<view class="user-section">
			<image class="bg" src="../../../static/user-bg.jpg"></image>
			<view class="user-info-box">
				<view class="portrait-box">
					<image class="portrait" src="../../../static/missing-face.png"></image>
				</view>
				<view class="info-box">
					<text class="username"> 昆工回收员</text>
				</view>
			</view>
			<view class="vip-card-box">
				<image class="card-bg" src="../../../static/vip-card-bg.png" mode=""></image>


			</view>
		</view>

		<view class="cover-container" :style="[{
				transform: coverTransform,
				transition: coverTransition
			}]" @touchstart="coverTouchstart" @touchmove="coverTouchmove" @touchend="coverTouchend">
			<image class="arc" src="/static/arc.png"></image>

			<view class="tj-sction">
				<view class="tj-item">
					<text class="num">{{user.balance}}</text>
					<text>店铺备用金</text>
				</view>
				<view class="tj-item">
					<text class="num">0</text>
					<text>昆工店</text>
				</view>
				<view class="tj-item">
					<text class="num">001</text>
					<text>工号</text>
				</view>
			</view>
			<!-- 订单 -->
			<view class="order-section">
				<view class="order-item" @click="navTo('/pages/invite/mine/order/order?selectedIndex=0')"
					hover-class="common-hover" :hover-stay-time="50">
					<view class="icon">
						<u-icon label="" size="20" name="clock-fill" color="#008080"></u-icon>
					</view>
					<text>待上门</text>
				</view>
				<view class="order-item" @click="navTo('/pages/invite/mine/order/order?selectedIndex=1')"
					hover-class="common-hover" :hover-stay-time="50">
					<view class="icon">
						<u-icon label="" size="20" name="thumb-up-fill" color="#008080"></u-icon>
					</view>
					<text>已完成</text>
				</view>
				<view class="order-item" @click="navTo('/pages/invite/mine/order/order?selectedIndex=2')"
					hover-class="common-hover" :hover-stay-time="50">
					<view class="icon">
						<u-icon label="" size="20" name="close-circle-fill" color="#008080"></u-icon>
					</view>
					<text>已取消</text>
				</view>
			</view>
			<!-- 浏览历史 -->
			<view class="history-section icon">

				<view class="message" @click="gotomoney">
					<view class="icon">
						<u-icon label="我的钱包" size="20" name="red-packet-fill" color="red"></u-icon>
					</view>
					<view class="icon-right">
						<u-icon label="" size="20" name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="message" @click="gotoRank">
					<view class="icon-left">
						<u-icon label="回收榜单" size="20" name="file-text-fill" color="#A3E4D7"></u-icon>
					</view>
					<view class="icon-right">
						<u-icon label="" size="20" name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="message">
					<view class="icon-left">
						<u-icon label="门店信息" size="20" name="home-fill" color="#f95959"></u-icon>
					</view>
					<view class="icon-right">
						<u-icon label="" size="20" name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="message" @click="gotoSet">
					<view class="icon-left">
						<u-icon label="设置" size="20" name="setting-fill"></u-icon>
					</view>
					<view class="icon-right">
						<u-icon label="" size="20" name="arrow-right"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="btns">
			<button v-if="this.user" id="myButton" type="primary" @click='outLogin'>退出登录</button>
			<button v-if="!this.user" id="myButton" type="primary" @click='login'>登录</button>
		</view>

		<view class="bottom">
			<!-- 底部导航栏 -->
			<u-tabbar :value="value1" @change="name => value1 = name" :fixed="true" :placeholder="true"
				:safeAreaInsetBottom="true">
				<u-tabbar-item text="接单大厅" icon="home" @click="click1"></u-tabbar-item>
				<u-tabbar-item text="待上门" icon="account" @click="click2"></u-tabbar-item>
				<u-tabbar-item text="我的" icon="account"></u-tabbar-item>
			</u-tabbar>
		</view>
	</view>
</template>
<script>
	import OrderApi from '@/common/FindingService/OrderApi.js';
	import {
		mapState
	} from 'vuex';
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {

		data() {
			return {
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
				value1: 2,
				user: '',
				userId: ''
			}
		},
		onLoad() {},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navTo('/pages/set/set');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		},
		// #endif
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		mounted() {
			this.userId = uni.getStorageSync('userId');
			this.clickUser()
		},
		methods: {
			login() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			outLogin() {
				if (!this.user) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				} else {
					uni.showToast({
						title: "退出成功",
						icon: "none",
						duration: 1000,

					})
					uni.navigateTo({
						url: '/pages/login/login'
					});
					this.loginOut(); //调用user.js的函数loginout
					// 删除本地缓存中的user数组
					uni.removeStorageSync('user');

					// 将computed属性中的user字段设为空数组
					this.user = [];
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/invite/mine/mine'
						});
					}, 1000);
				}
			},
			gotoSet() {
				uni.navigateTo({
					url: '/pages/set/set'
				})
			},
			gotoRank() {
				uni.navigateTo({
					url: '/pages/invite/mine/ranking/ranking'
				})
			},
			gotomoney() {
				uni.navigateTo({
					url: '/pages/invite/mine/integral/integral'
				})
			},
			//加载用户
			clickUser() {
				OrderApi.queryUser(this.userId).then(res => {
					this.user = res.data.data

					console.log('用户', this.user)
					uni.setStorageSync('updatedUser', this.newUser);
					this.user.balance = res.data.data.balance.toFixed(1);

				})
			},
			click2() {
				uni.navigateTo({
					url: '/pages/invite/wait/wait'

				});
			},
			click1() {
				uni.navigateTo({
					url: '/pages/invite/invite'

				});
			},

			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {

				uni.navigateTo({
					url
				})
			},

			/**
			 *  会员卡下拉和回弹
			 *  1.关闭bounce避免ios端下拉冲突
			 *  2.由于touchmove事件的缺陷（以前做小程序就遇到，比如20跳到40，h5反而好很多），下拉的时候会有掉帧的感觉
			 *    transition设置0.1秒延迟，让css来过渡这段空窗期
			 *  3.回弹效果可修改曲线值来调整效果，推荐一个好用的bezier生成工具 http://cubic-bezier.com/
			 */
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			}
		}
	}
</script>
<style lang='scss'>
	//退出登录1
	.btns {
		margin-left: -20rpx;
		margin-right: -20rpx;

		padding: 50rpx;

	}

	.btn {}

	.container {
		height: 100vh;
		width: 100%;
		background-color: #F5F5F5;

	}

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 10upx;
	}

	.user-section {
		height: 520upx;
		padding: 100upx 30upx 0;
		position: relative;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			filter: blur(1px);
			opacity: .7;
		}
	}

	.user-info-box {
		height: 180upx;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1;

		.portrait {
			width: 130upx;
			height: 130upx;
			border: 5upx solid #fff;
			border-radius: 50%;
		}

		.username {
			font-size: 16px;
			color: #000;
			margin-left: 20upx;
		}
	}

	.vip-card-box {
		display: flex;
		flex-direction: column;
		color: #f7d680;
		height: 240upx;
		background: linear-gradient(left, rgba(0, 0, 0, .7), rgba(0, 0, 0, .8));
		border-radius: 16upx 16upx 0 0;
		overflow: hidden;
		position: relative;
		padding: 20upx 24upx;

		.card-bg {
			position: absolute;
			top: 20upx;
			right: 0;
			width: 380upx;
			height: 260upx;
		}

		.b-btn {
			position: absolute;
			right: 20upx;
			top: 16upx;
			width: 132upx;
			height: 40upx;
			text-align: center;
			line-height: 40upx;
			font-size: 22upx;
			color: #36343c;
			border-radius: 20px;
			background: linear-gradient(left, #f9e6af, #ffd465);
			z-index: 1;
		}

		.tit {
			font-size: 16px;
			color: #000;
			margin-bottom: 28upx;

			.yticon {
				color: #f6e5a3;
				margin-right: 16upx;
			}
		}

		.e-b {
			font-size: 16px;
			color: #d8cba9;
			margin-top: 10upx;
		}
	}

	.cover-container {
		background: #000;
		margin-top: -150upx;
		padding: 0 30upx;
		position: relative;
		background: #f5f5f5;
		padding-bottom: 20upx;


		.arc {
			position: absolute;
			left: 0;
			top: -34upx;
			width: 100%;
			height: 36upx;
		}
	}

	.tj-sction {
		@extend %section;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: 16px;
			color: #75787d;
		}

		.num {
			font-size: 16px;
			color: #000;
			margin-bottom: 8upx;
		}
	}

	.order-section {
		@extend %section;
		padding: 28upx 0;
		margin-top: 20upx;

		.order-item {
			@extend %flex-center;
			width: 130upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: 16px;
			color: dark;
		}

		.yticon {
			font-size: 48upx;
			margin-bottom: 18upx;
			color: #fa436a;
		}

		.icon-shouhoutuikuan {
			font-size: 44upx;
		}
	}

	.history-section {
		padding: 50rpx 30rpx;
		margin-top: 20upx;
		background: #fff;
		border-radius: 10upx;


	}

	.message {
		border-bottom: 1px solid #f5f5f5;
		font-size: 16px;
		margin-bottom: 20rpx;
		height: 60rpx;
		display: flex;
		justify-content: space-between;
	}
</style>